/* 
 * File:   bit_io.h
 * Author: igor
 *
 * Created on 9 ������ 2008 �., 11:11
 */

#ifndef _BIT_IO_H
#define	_BIT_IO_H

#include "bza_types.h"

typedef enum
{
	BZA_BITIO_MODE_NONE = 0,
	BZA_BITIO_MODE_WRITE,
	BZA_BITIO_MODE_READ,
} BZA_BitIo_Mode;


class BZA_BitIo
{
	private:
		BZA_SIZE		file_pos;
		BZA_BitIo_Mode	mode;
		
		BZA_BYTE*		buffer;
		BZA_SIZE		buffer_byte_pos;
		int				buffer_bit_pos;
	
	public:
		/* Constructor/destructor */
		BZA_BitIo();
		~BZA_BitIo();
		bool		set_options( char* _filename, BZA_BitIo_Mode _mode, BZA_SIZE _initial_pos_in_file );
		
		/* Buffer operations */
		void*		get_buffer( void );
		void		set_buffer( void* _buffer );
		bool		flush( void );
		
		/* Bit operations */
		void		write_bit( int _bit );
		void		write_value( BZA_SIZE _value, int _bit_count );
		
		int			read_bit( void );
		BZA_SIZE	read_value( int _bit_count );
};


#endif	/* _BIT_IO_H */

